import userTempId from "@/utils/userTempId"
import{getItem,setItem,removeItem} from "@/utils/localStorage"
import {reqLogin,reqUserMessage} from '@/api';
const state = {
    userTempId : userTempId(),
    token : getItem("token") || "",
    userMessage : {}
}
const mutations ={
    //设置token
   set_token(state,payload){
    state.token = payload.token
    setItem("token", payload.token)
   },
   set_userMessage(state,payload){
    state.userMessage = payload.userMessage
   },
   
   remove_token(state){
    state.token = ""
    removeItem("token")
    state.userMessage={}
    
   }
}
const actions = {
  async getToken({commit},userInfo){
   const result = await reqLogin(userInfo)
    commit("set_token",{token:result.token})
  },

  async getUserMessage({commit}){
    const result = await reqUserMessage()
    commit("set_userMessage",{userMessage : result})
    
  }
}
const getters = {}
export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}